<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox
        v-for="item in list"
        :key="item.id"
        :label="item.id"
        :value="item.name"
      ><template>{{ item.name }}</template></el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="Hsave">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getRoles } from '@/api/settings'
import { getUserDetailById } from '@/api/user'
import { assignRoles } from '@/api/employee'
export default {
  props: {
    cruId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      roleIds: [],
      list: []
    }
  },
  created() {
    this.loadRolelist()
    this.loadRoleAssign()
  },
  methods: {
    async Hsave() {
      await assignRoles({ id: this.cruId, roleIds: this.roleIds })
      this.$emit('Hsuccess')
    },
    async loadRoleAssign() {
      const res = await getUserDetailById(this.cruId)
      this.roleIds = res.data.roleIds
    },
    async loadRolelist() {
      const res = await getRoles({ page: 1, pagesize: 100 })
      this.list = res.data.rows
    },
    closeDialog() {}
  }
}
</script>
